<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>电脑均衡分班</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form label-width="80px" ref="editForm">
          <el-form-item label="分班数:">
            <el-input v-model="classNumber" placeholder="填写分班数" class="w-140" size="small"></el-input>
          </el-form-item>
          <!--          <el-form-item label="导入分班学生:">-->
          <!--            <el-upload-->
          <!--                class="upload-demo"-->
          <!--                :action="imgSrcHttp"-->
          <!--                :on-remove="handleRemove"-->
          <!--                :on-success="handleSuccess"-->
          <!--                :before-upload="beforeAvatarUpload"-->
          <!--                :file-list="fileList"-->
          <!--                multiple-->
          <!--                accept=".xlsx,.xls"-->
          <!--                :limit="1"-->
          <!--                v-if="classNumber">-->
          <!--              <el-button size="small" class="el-icon-upload">点击上传</el-button>-->
          <!--              <div slot="tip" class="el-upload__tip">只能上传excel文件</div>-->
          <!--            </el-upload>-->
          <!--            <el-button size="small" class="el-icon-upload" v-else disabled>请先填写分班数</el-button>-->
          <!--          </el-form-item>-->
          <el-form-item label="分班规则:">
            <el-checkbox-group
                v-model="cities">
              <el-checkbox v-for="city in checkedCities" :label="city" :key="city" disabled>{{ city }}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <!--          <el-form-item label="导出分班:">-->
          <!--            <el-button size="small"  @click="getFileFn">导出分班excel结果文件</el-button>-->
          <!--            <el-button size="small" @click="removeFileFn">清空文件重新上传</el-button>-->
          <!--          </el-form-item>-->
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">关闭</el-button>
        <el-button @click="getFileFn" size="small" plain type="primary">确定并导出分班结果文件</el-button>
      </div>
      <div style="display: none">
        <iframe :src="downLoadFile" frameborder="0" v-if="downLoadFile"></iframe>
      </div>
    </div>
    <!--    <studentExcel  :visible.sync="excelVisible"></studentExcel>-->
  </div>
</template>

<script>
// import studentExcel from "./components/studentExcel";
import {studyPushClass} from "@/api/admin/student"

export default {
  props: ['visible', 'studentInfo'], // commoent 学生点评 collection 学生采集
  components: {},
  data() {
    return {
      excelVisible: false,
      dialogVisible: false,
      excelData: '',
      editForm: {},
      fileList: [],
      file: '',
      downLoadFile: '',
      checkedCities: ['性别均衡', '月龄均衡', '双胞胎均衡', '人数均衡', '外籍均衡'],
      cities: ['性别均衡', '月龄均衡', '双胞胎均衡', '人数均衡', '外籍均衡'],
      classNumber: ''
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (!this.visible) {
        this.classNumber = ''
      }
    }
  },
  created() {
  },
  methods: {
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getFileFn() {
      let n = this
      if (!this.classNumber) {
        this.$message.error('请填写分班数')
        return
      }
      studyPushClass({list: JSON.stringify(this.studentInfo), number: this.classNumber}).then(res => {
        console.log('res:', res)
        if (!res.code) {
          n.downLoadFile = ''
          setTimeout(() => {
            n.downLoadFile = res.file
          }, 300)
        }
      })
    },
    // removeFileFn() {
    //   this.fileList = [];
    //   this.downLoadFile = '';
    //   this.file = '';
    // },
    handleRemove(file, fileList) {
      console.log('移除', file, fileList)
      this.file = ''
    },
    handleSuccess(response) {
      this.editForm.file = response.data.name
      // 上传成功后传入后台
      this.uploadFileFn(response.data.name)
    },
    // 初始化
    async uploadFileFn(option) {
      let data = await this.$fetch(this.api.common.division, {file: option, number: this.classNumber});
      if (!data.code) {
        this.file = this.$openBASE_URL('img') + data.file
      } else {
        this.$message.error(data.msg)
      }
    },
    beforeAvatarUpload(file) {
      // console.log('提交之前：', file)
      // if(!this.classNumber){
      //   this.$message.error('填写分班的数量')
      // }
      // return !this.classNumber
      // const isLt2M = file.size / 1024 / 1024 < 2
      // if (!isLt2M) {
      //   this.$message.error('上传头像图片大小不能超过 2MB!')
      // }
      // return isLt2M
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 50%;
  height: auto;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}
</style>


